package oop.ex1.actions;

import java.io.File;
import java.io.IOException;
//###############
//FILE : DiskAttributesFilter.java
//WRITER : Amir Wilf, wilfoa, 300007085
//WRITER : Daniel Acherkan, danithelion, 310116348
//EXERCISE : oop ex1 2011
//DESCRIPTION:
//A Print action class - an action that prints file data onto the standard
//output
//###############
public class PrintAction implements Action{
		
	/**
	 * Prints data of a given file.
	 * @param file the file to be printed. 
	 */
	public void doAction(File file){
		//printing file attributes
		if(file.canRead()){
			System.out.print("r");
		}
		else{
			System.out.print("-");
		}
		if(file.canWrite()){
			System.out.print("w");
		}
		else{
			System.out.print("-");
		}
		if(file.canExecute()){
			System.out.print("x ");
		}
		else{
			System.out.print("- ");
		}
		//printing file size and path
		try {
			System.out.print(file.length() + " " +
					file.getCanonicalPath().toString() + "\n");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
